import {Injectable} from "@angular/core";
import {Observable} from "rxjs/Observable";
import {API} from "../constants/constants";
import {RequestUtil} from "../util/request-util";
import {LogUtil} from "../util/log-util";

@Injectable()
export class PortalsService {

  constructor(
    private requestUtil: RequestUtil,
    private logUtil:LogUtil
  ) { }
  //authorization/types/{menus|operations|resources}
  getPermissions(type:string):Observable<any>{
    if(!!!type){
      this.logUtil.warn("request cancel");
      return;
    }
    let uri = API.getPermissions+type+".json";
    return this.requestUtil.get(uri);
  }

  getFisrtLevelMenus():Observable<any>{
    let uri = API.getFirstLevelMenus;
    return this.requestUtil.get(uri);
  }
  getChildMenus(id:string):Observable<any>{
    let uri = API.getChildMenus.replace("{id}",id);
    return this.requestUtil.get(uri);
  }
}
